//
//  NearbyShopsCell.swift
//  XiaoJingMallSwift
//
//  Created by beisheng03 on 2017/8/7.
//  Copyright © 2017年 beisheng. All rights reserved.
//

import UIKit

class NearbyShopsCell: BaseTableViewCell {
    
    @IBOutlet weak var leftImageView: UIImageView!
    
    @IBOutlet weak var topLabel: UILabel!
    
    @IBOutlet weak var bottomLabel: UILabel!
    
    @IBOutlet weak var bgView: UIView!
    
    @IBOutlet weak var inditorView: UIActivityIndicatorView!
    
    @IBOutlet weak var rightLabelW: NSLayoutConstraint!
    
    @IBOutlet weak var distansLabel: UILabel!
    
    lazy var testLabel : UILabel = {
        
        let temp = UILabel()
        
        temp.font = UIFont.systemFont(ofSize: 13)
        
        return temp
        
        
    }()
    
    lazy var starView : StarView = {
        
        let temp = Bundle.main.loadNibNamed(self.StringFromClass(classType: StarView.self), owner: nil, options: nil)?.first as! StarView
        
        
        return temp
        
    }()
    
    
    var model : ShopInfoModel?{
    
        didSet{
        
            if model != nil {
                
                inditorView.startAnimating()
                leftImageView.sd_setImage(with: URL(string: model!.img_url), placeholderImage: UIImage.defaulImage(), options: []) { (image, _, _, _) in
                    self.inditorView.stopAnimating()
                    
                    
                }

                testLabel.text = "\(model!.distance)KM"
                testLabel.sizeToFit()
                
                rightLabelW.constant = testLabel.bounds.size.width
                
                topLabel.text = model?.merchant_name
                bottomLabel.text = model?.merchant_class_text
                distansLabel.text = "\(model!.distance)KM"
                
                if let temp = Int(model!.merchant_star){
                    
                    starView.starCount = temp
                    
                    
                }

                
            }
        
        }
    
    
    }
    

    override func awakeFromNib() {
        super.awakeFromNib()
        contentView.backgroundColor = UIColor.white
        bgView.addSubview(starView)
        topLabel.textColor = UIColor.black
        topLabel.font = UIFont.systemFont(ofSize: 15)
        bottomLabel.textColor = UIColor.dakGray()
        bottomLabel.font = UIFont.systemFont(ofSize: 13)
        distansLabel.textColor = UIColor.dakGray()
        distansLabel.font = UIFont.systemFont(ofSize: 13)

    }
    
    
    override func layoutSubviews() {
        
        super.layoutSubviews()
        
        starView.frame = bgView.bounds
        

           
    }
    

    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

        // Configure the view for the selected state
    }
    
}
